//
//  FontFamilyViewController.m
//  TextToImg
//
//  Created by Garenge on 2019/12/19.
//  Copyright © 2019 鹏鹏. All rights reserved.
//

#import "FontFamilyViewController.h"
#import <Masonry/Masonry.h>
#import "AppTool.h"

@interface FontFamilyViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSArray *familyNames;

@end

@implementation FontFamilyViewController

static NSString *showString = @"字体展示";

- (NSArray *)familyNames {
    if (nil == _familyNames) {
        _familyNames = [UIFont familyNames];
    }
    return _familyNames;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"所有字体";
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
}

#pragma mark tableView delageta, datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.familyNames.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (nil == cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    NSString *fontName = self.familyNames[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@-%@", showString, fontName];
    cell.textLabel.font = APPUsualFontWithNameAndSize(fontName, 20);
    return cell;
}


@end
